import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";
import { pluginImageCompress } from "@rsbuild/plugin-image-compress";
import { pluginLess } from "@rsbuild/plugin-less";

// -> https://juejin.cn/post/7411354460968665103
// -> rsbuild配置文档：https://rsbuild.dev/zh/config/index
// -> https://rsbuild.dev/zh/plugins/list/#%E9%80%9A%E7%94%A8%E6%8F%92%E4%BB%B6

export default defineConfig({
  plugins: [
    pluginReact(),
    // pluginImageCompress(),
    pluginLess(),
  ],

  // html页面
  html: {
    title: "测试111",
    template: "./public/index.html",
    favicon: "./src/assets/favicon.png",
    mountId: "root",
  },

  // 代码优化和上线配置
  performance: {
    chunkSplit: {
      strategy: "split-by-experience",
    },
    removeConsole: true, // 生产模式构建时，是否自动移除代码中所有的 console.[methodName]
    bundleAnalyze: {
      openAnalyzer: false,
    }, // 开启分析产物体积，生成 ./dist/report-web.html 文件
  },

  // 别名
  source: {
    alias: {
      "@": "./src",
    },
  },

  // 打包输出配置
  output: {
    cleanDistPath: true,
    filenameHash: "fullhash:16",
    sourceMap: true,
  },

  //开发环境服务配置,跨域处理
  server: {
    base: "/",
    host: "0.0.0.0",
    open: true,
    port: 1000,
    htmlFallback: "index",
    proxy: {
      "/api": {
        changeOrigin: true,
        ws: true,
        target: "http://localhost:7100",
        pathRewrite: { "^/api": "" },
      },
    },
  },
});

// -》 https://blog.csdn.net/qq_37753933/article/details/104604518
